package com.felix.tests;

import felix.things.router.opc.rpc.RpcEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Random;

@Component
@EnableScheduling
public class OpcuaWriteTest {

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;
    private Random random = new Random();

//    @Scheduled(fixedDelay = 3000)
    public void write() {
        HashMap<String, Object> command = new HashMap<>();
        int i = random.nextInt(100);
        command.put("通道 1.设备 1.标记 2", i);
        RpcEvent rpcEvent = new RpcEvent(this, "kerpserver", "设备 1_标记 2", command);
        applicationEventPublisher.publishEvent(rpcEvent);
        System.out.println("写入成功  " + i);
    }
}
